package top.xiangqifu.springboot2.user.base;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class BaseDataResult<T> extends BaseResult {
    private T data;

    public static <T> BaseDataResult<T> instance(int code, String message, boolean success, T data) {
        BaseDataResult<T> result = new BaseDataResult<>();
        result.buildInfo(code, message, success);
        result.setData(data);
        return result;
    }

    public static <T> BaseDataResult<T> ok(int code, String message, T data) {
        return instance(code, message, true, data);
    }

    public static <T> BaseDataResult<T> ok(String message, T data) {
        return instance(SUCCESS_CODE, message, true, data);
    }

    public static <T> BaseDataResult<T> ok(T data) {
        return instance(SUCCESS_CODE, "", true, data);
    }

    public static <T> BaseDataResult<T> failNoData(int code, String message) {
        BaseDataResult<T> result = new BaseDataResult<>();
        result.buildInfo(code, message, false);
        return result;
    }

    public static <T> BaseDataResult<T> failNoData(String message) {
        return failNoData(ERROR_CODE, message);
    }

    public static <T> BaseDataResult<T> fail(String message, T data) {
        return instance(ERROR_CODE, message, false, data);
    }

}
